#!/usr/bin/env node

// 如果是 Linux 或者 macOS 系统下需要修改文件的读写权限为 755
// chmod 755 cli.js

const fs = require('fs')
const path = require('path')
const inquirer = require('inquirer')


console.log("正在创建项目...")
inquirer.prompt([
  {
    type: 'input',
    name: 'name',
    message: 'project name: '
  }, {
    type: 'input',
    name: 'author',
    message: 'author name: '
  }, {
    type: 'input',
    name: 'description',
    message: 'description: '
  }
]).then(res => {
  // 用户回答结果

  const tmplDir = path.join(__dirname, 'templates')
  const destDir = process.cwd()

  fs.readdir(tmplDir, (err, files) => {
    if (err) throw err
    files.forEach(file => {
      ejs.renderFile(path.join(tmplDir, file), res, (err, result) => {
        if (err) throw err
        fs.writeFileSync(path.join(destDir, file), result)
      })
    })
  })
})